package cn.witsky.rtp2ws.client.ws.netty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.witsky.rtp2ws.domain.Rtp;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;

public class NettyChannelFutureListener implements ChannelFutureListener {
	private static Logger logger = LoggerFactory.getLogger(NettyChannelFutureListener.class);
	Rtp rtp;

	public NettyChannelFutureListener(Rtp rtp) {
		this.rtp = rtp;
	}

	@Override
	public void operationComplete(ChannelFuture future) throws Exception {
		// TODO Auto-generated method stub
		if (future.isSuccess()) {
			this.success();
		} else {
			this.error(future);
		}
	}
	void success() {
		rtp.getSendSucCount().incrementAndGet();

	}

	void error(ChannelFuture future) {
		logger.error("ws 发送消息失败 call:" + rtp.getRtpId(), future.cause());
		rtp.getSendErrCount().incrementAndGet();

	}
}
